package com.ruoyi.web.controller.wq;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysUser;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.wq.domain.WqUserPlay;
import com.ruoyi.wq.domain.vo.WqUserPlayVO;
import com.ruoyi.wq.service.IWqUserPlayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.web.service.PlayService;
import com.ruoyi.system.service.ISysUserService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 达人陪玩Controller
 * 
 * @author ruoyi
 * @date 2023-09-05
 */
@RestController
@RequestMapping("/wq/userPlay")
public class WqUserPlayController extends BaseController {

    @Autowired
    private IWqUserPlayService wqUserPlayService;
    
    @Autowired
    private ISysUserService sysUserService;
    
    @Autowired
    private PlayService playService;
    
    /**
     * 查询陪玩列表
     */
    @Anonymous
    @GetMapping("/getList")
    public TableDataInfo getList(WqUserPlayVO wqUserPlay){
        TableDataInfo info = wqUserPlayService.getUserPageList(wqUserPlay);
        return info;
    }

    /**
     * 查询申请列表
     */
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(WqUserPlayVO wqUserPlay){
        TableDataInfo info = wqUserPlayService.getPageList(wqUserPlay);
        return info;
    }

    /**
     * 导出达人陪玩列表
     */
    @PreAuthorize("@ss.hasPermi('wq:userPlay:export')")
    @Log(title = "达人陪玩", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, WqUserPlay wqUserPlay)
    {
        List<WqUserPlay> list = wqUserPlayService.selectWqUserPlayList(wqUserPlay);
        ExcelUtil<WqUserPlay> util = new ExcelUtil<WqUserPlay>(WqUserPlay.class);
        util.exportExcel(response, list, "达人陪玩数据");
    }

    /**
     * 获取达人陪玩详细信息
     */
    @PreAuthorize("@ss.hasPermi('wq:userPlay:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(wqUserPlayService.selectWqUserPlayById(id));
    }

    /**
     * 添加项目
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WqUserPlay wqUserPlay){
        return AjaxResult.success(wqUserPlayService.saveUserPlay(wqUserPlay));
    }
    
    /**
     * 添加项目
     */
    @PostMapping("/playSuccess")
    public AjaxResult add(@RequestBody WqUserPlayVO wqUserPlay){
        return AjaxResult.success(playService.playSuccess(wqUserPlay));
    }
    
    /**
     * 获取活动详细信息
     */
    @Anonymous
    @GetMapping(value = "/getDetail")
    public AjaxResult getDetail(Long userId){
    	AjaxResult ajax = AjaxResult.success();
    	SysUser user = sysUserService.getById(userId);
    	List<WqUserPlayVO> playList = wqUserPlayService.getPlayList(userId);
    	ajax.put("user", user);
    	ajax.put("playList", playList);
        return ajax;
    }

    /**
     * 修改达人陪玩
     */
    @PreAuthorize("@ss.hasPermi('wq:userPlay:edit')")
    @Log(title = "达人陪玩", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody WqUserPlay wqUserPlay)
    {
        return toAjax(wqUserPlayService.updateWqUserPlay(wqUserPlay));
    }

    /**
     * 删除达人陪玩
     */
    @PreAuthorize("@ss.hasPermi('wq:userPlay:remove')")
    @Log(title = "达人陪玩", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(wqUserPlayService.deleteWqUserPlayByIds(ids));
    }
}
